#include <bits/stdc++.h>
using namespace std;
#define yes cout << "YES" << endl
#define no cout << "NO" << endl
using ll = long long;
const ll N = 5e3 + 10;
ll a[N];
void solve()
{
    ll n;
    ll k;
    cin >> n;
    cin >> k;

    for (ll i = 1; i <= n; i++)
    {
        cin >> a[i];
        // cout << a[i] << " ";
    }
    // cout << endl;
    if (k <= 1)
    {
        ll ans = -1;
        for (ll i = 1; i <= n; i++)
        {
            if (i == 1)
                continue;
            else
                ans = max(ans, a[1] + a[i]);
        }

        for (ll i = 1; i <= n; i++)
        {
            if (i == n)
                continue;
            else
                ans = max(ans, a[n] + a[i]);
        }
        cout << ans << endl;
    }
    else
    {

        ll ans = 0;
        sort(a+1 , a+n+1,greater<ll>());
        for (ll i = 1; i <= n;i++)
        {
            if(i<=k+1)
            {
                ans += a[i];
            }
            else
                break;
        }
        cout << ans << endl;
    }
}
int main()
{
    int t = 1;
    cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}
